package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.utils.FileUploadUtils;
import org.apache.commons.io.FilenameUtils;
import org.csource.fastdfs.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.util.ClassUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 李旭
 * @date 2022/1/4 11:12
 * @Description:
 *
 * 上传文件
 *
 */
@RestController
@RequestMapping("/admin/product")
@RefreshScope //扩展配置文件一旦发生变化 马上更新
public class FileController {

    @Value("${image.url}")
    private String imageUrl;

    @Autowired
    private FileUploadUtils fileUploadUtils;

    //上传文件
    @PostMapping("/fileUpload")
    public Result fileUpload(MultipartFile file) throws Exception{

        System.out.println(file.getSize());
        System.out.println(file.getName());
        System.out.println(file.getOriginalFilename());
        //System.out.println(file.getBytes());
        String path = fileUploadUtils.upload(file.getOriginalFilename(), file.getBytes());
        System.out.println(imageUrl + path);
        return Result.ok(imageUrl + path);
    }

    //上传订单图片

    //上传

}
